/*
 * Project: Hades TCK Tests
 *
 * File Created at 2012-03-12
 * by tingjia.chentj
 *
 * Copyright 2012 B2B Technology, Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with B2B Technology, Alibaba.com.
 */
package com.glamour.hlcity.testng.listener;

import org.springframework.context.ApplicationContext;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;

import com.glamour.hlcity.testng.common.TestApplicationContextHolder;

/**
 * 实现Spring Bean的注入
 *
 * @author tingjia.chentj
 */
public abstract class AbstractInjectBeanTestListener extends AbstractDummyTestListener implements TestApplicationContextHolder.Callback {

    /**
     * 用于测试的Bean注册文件路径
     */
    private static final String[] TESTNG_BEAN_LOCATIONS = new String[] {
//        "classpath*:META-INF/spring/testng-beans.xml",
//        "classpath*:META-INF/spring/testng-beans-*.xml"

    };

    /**
     * 用于测试的Mock注册文件路径
     */
    private static final String[] TESTNG_MOCK_LOCATIONS = new String[] {
         // "classpath*:META-INF/log4j.xml",
//        "classpath*:META-INF/spring/mock/testng-mock-*.xml"
    };

    @Override
    public void onStart(ITestContext context) {
    	TestApplicationContextHolder holder = TestApplicationContextHolder.instance().context(this);
        ITestNGMethod[] methods = context.getAllTestMethods();
        for (ITestNGMethod method : methods) {
            holder.injectBeansByName(method.getInstance());
        }
    }

    @Override
    public String[] getTestBeanConfigLocations() {
        return TESTNG_BEAN_LOCATIONS;
    }

    @Override
    public String[] getTestMockConfigLocations() {
        return TESTNG_MOCK_LOCATIONS;
    }

    @Override
    public void afterApplicationContextLoad(ApplicationContext context) {
    }
}
